package com.blb.examsystem.filter;
import com.blb.common.entity.QuestionSet;
import com.blb.common.entity.Subject;
import com.blb.common.utils.DBUtils;
import com.blb.common.utils.SpringUtils;
import com.blb.examsystem.service.QuestionSetService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.util.List;

/**
 * @author lvtian
 * @date 2022/11/29 10:39
 */
@WebFilter({"/addQuestionSet.html","/updateQuestionSet.html","/findQuestionSetById","/addQuestion.html","/updateQuestion.html","/findQuestionById"})
public class addComFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        List<QuestionSet> questionSets = DBUtils.executeQuery(QuestionSet.class, "select * from t_question_set ");
        //subject名
        List<Subject> subjects = DBUtils.executeQuery(Subject.class, "select * from t_subject");
        servletRequest.setAttribute("subjects",subjects);
        servletRequest.setAttribute("questionSets",questionSets);
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
